package com.yj.cmp.sdk.fusioncompute.compute.cluster;

import com.yj.cmp.sdk.fusioncompute.common.utils.RequestUtils;
import com.yj.cmp.sdk.fusioncompute.compute.cluster.vo.ClusterDetailVO;
import com.yj.cmp.sdk.fusioncompute.compute.cluster.vo.ClusterListVo;
import lombok.Data;
import org.springframework.stereotype.Component;
import retrofit2.Response;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Harvey_Yang
 * @date 2021/8/28 11:13
 */
@Data
@Component
public class FcClusterApi {

    FcClusterService fcClusterInterface;

    public FcClusterApi(FcClusterService fcClusterInterface) {
        this.fcClusterInterface = fcClusterInterface;
    }

    /**
     * 查询集群列表
     *
     * @param headerMap
     * @return
     * @throws Exception
     */
    public List<ClusterListVo.ClustersDTO> clusterList(Map<String, Object> headerMap) throws Exception {
        Response<ClusterListVo> response = fcClusterInterface.clusterList(headerMap).execute();
        RequestUtils.isSuccessful(response);
        if (null != response.body()) {
            return response.body().getClusters();
        }
        return new ArrayList<>(0);
    }


    /**
     * 查询集群详细
     *
     * @param headerMap
     * @param clustersId
     * @return
     * @throws Exception
     */
    public ClusterDetailVO clusterDetail(Map<String, Object> headerMap, String clustersId) throws Exception {
        Response<ClusterDetailVO> response = fcClusterInterface.clusterDetail(headerMap, clustersId).execute();
        RequestUtils.isSuccessful(response);
        if (null != response.body()) {
            return response.body();
        }
        return new ClusterDetailVO();
    }
}
